import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';

import { BaseDirective } from '../../core/models/base-directive.model';
import { UserService } from '../shared/user.service';

@Component({
    selector: 'op-user-detail',
    templateUrl: './user-detail.component.html',
})
export class UserDetailComponent extends BaseDirective implements OnInit {
    userInfo: any = {};
    imageList: any = [];

    constructor(
        private userService: UserService,
        private route: ActivatedRoute
    ) {
        super();
    }

    ngOnInit(): void {
        super.ngOnInit();
        
        this.getUserInfo();
    }

    getUserInfo(): void {
        this.route.paramMap.subscribe(data => {
            let id = data.get('id');

            let user = {
                userCode: id
            };

            this.userService.getUserDeatilInfo(user).subscribe(data => {
                let user = data.filter(user => user.userCode === id);
                this.userInfo = user[0];
                this.imageList = user[0].imageList;
            });
        });
    }

    // getUserInfo(): void {
    //     this.route.paramMap.subscribe(data => {
    //         let id = +data.get('id');

    //         let user = {
    //             userCode: id
    //         };

    //         this.userService.getUserDeatilInfo(user).subscribe(data => {
    //             this.userInfo = data.result[0];
    //             this.imageList = data.result[0].imageList;
    //         });
    //     });
    // }
}